package com.graduation.project.controller.process;

import com.graduation.project.entity.dto.task.ListTaskDTO;
import com.graduation.project.entity.dto.assignmentBook.SaveOrUpdateAssignmentDTO;
import com.graduation.project.entity.dto.UpdateStatusDTO;
import com.graduation.project.service.process.AssignmentBookService;
import com.graduation.project.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/assignment")
public class AssignmentBookController {

    @Autowired
    private AssignmentBookService assignmentBookService;

    /**
     * 获取课题下拉数据
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:assignment:add')")
    @GetMapping("/get/getTaskOptions")
    public ResultUtil<?> getTaskOptions() {
        return assignmentBookService.getTaskOptions();
    }

    /**
     * 获取任务书详情
     * @param id 任务书id
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:assignment:update', 'pro:assignment:details')")
    @GetMapping("/get/getAssignmentBookDetails")
    public ResultUtil<?> getAssignmentBookDetails(@RequestParam("id") Long id) {
        return assignmentBookService.getAssignmentBookDetails(id);
    }

    /**
     * 新增任务书
     * @param input 新增|修改任务书输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:assignment:add')")
    @PostMapping("/post/addAssignmentBook")
    public ResultUtil<?> addAssignmentBook(@RequestBody SaveOrUpdateAssignmentDTO input) {
        return assignmentBookService.addAssignmentBook(input);
    }

    /**
     * 修改任务书
     * @param input 新增|修改任务书输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:assignment:update')")
    @PutMapping("/put/updateAssignmentBook")
    public ResultUtil<?> updateAssignmentBook(@RequestBody SaveOrUpdateAssignmentDTO input) {
        return assignmentBookService.updateAssignmentBook(input);
    }

    /**
     * 删除任务书
     * @param id 任务书id
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:assignment:delete')")
    @DeleteMapping("/delete/deleteAssignmentBook")
    public ResultUtil<?> deleteAssignmentBook(@RequestParam("id") Long id) {
        return assignmentBookService.deleteAssignmentBook(id);
    }

    /**
     * （条件）查询任务书
     * @param input 条件查询任务书输入类
     * @return ResultUtil
     */
    @PostMapping("/post/listAssignmentBookByCondition")
    public ResultUtil<?> listAssignmentBookByCondition(@RequestBody ListTaskDTO input) {
        return assignmentBookService.listAssignmentBookByCondition(input);
    }

    /**
     * 审核任务书
     * @param input 修改状态输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:assignment:audit')")
    @PutMapping("/put/auditAssignmentBook")
    public ResultUtil<?> auditAssignmentBook(@RequestBody UpdateStatusDTO input) {
        return assignmentBookService.auditAssignmentBook(input);
    }
}
